﻿//==========================================================
// 此代码由TilverNET代码生成工具自动生成，请不要修改
// 代码生成器版本号：1.2
// 作者：landy
// 联系方式：(QQ)86566178
// 创建时间：2014-10-13 11:00:48
//==========================================================

using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using Tilver.Data;
using Tilver.Data.DataPager;

namespace Weather.DAL.CoWeather
{
	#region EO

	/// <summary>
	///  《dbo.T_Sign_Info(实体类)》
	/// </summary>
	[Serializable]
	public class TSignInfoEO : IRowMapper<TSignInfoEO>
	{
		protected string _signId;
		protected string _signType;
		protected string _signClass;
		protected byte[] _signImage;
		protected string _signContent;
		protected string _signDefence;
		protected int? _signValidity;


		/// <summary>
		///  《[字段]  [char]》
		/// </summary>
		public string SignId
		{
			get { return _signId; }
			set { _signId = value;}
		}

		/// <summary>
		///  《[字段]  [varchar]》
		/// </summary>
		public string SignType
		{
			get { return _signType; }
			set { _signType = value;}
		}

		/// <summary>
		///  《[字段]  [varchar]》
		/// </summary>
		public string SignClass
		{
			get { return _signClass; }
			set { _signClass = value;}
		}

		/// <summary>
		///  《[字段]  [image]》
		/// </summary>
		public byte[] SignImage
		{
			get { return _signImage; }
			set { _signImage = value;}
		}

		/// <summary>
		///  《[字段]  [text]》
		/// </summary>
		public string SignContent
		{
			get { return _signContent; }
			set { _signContent = value;}
		}

		/// <summary>
		///  《[字段]  [text]》
		/// </summary>
		public string SignDefence
		{
			get { return _signDefence; }
			set { _signDefence = value;}
		}

		/// <summary>
		///  《[字段]  [int]》
		/// </summary>
		public int? SignValidity
		{
			get { return _signValidity; }
			set { _signValidity = value;}
		}

		/// <summary>
		/// 默认构造函数
		/// </summary>
		public TSignInfoEO() 
		{
			SignId = string.Empty;
			SignType = string.Empty;
			SignClass = string.Empty;
			SignContent = string.Empty;
			SignDefence = string.Empty;
		}

		/// <summary>
		/// 自定义构造函数
		/// </summary>
		/// <param name = "signId"></param>
		/// <param name = "signType"></param>
		/// <param name = "signClass"></param>
		/// <param name = "signImage"></param>
		/// <param name = "signContent"></param>
		/// <param name = "signDefence"></param>
		/// <param name = "signValidity"></param>
		public TSignInfoEO(string signId, string signType, string signClass, byte[] signImage, string signContent, string signDefence, int? signValidity) 
		{
			_signId = signId;
			_signType = signType;
			_signClass = signClass;
			_signImage = signImage;
			_signContent = signContent;
			_signDefence = signDefence;
			_signValidity = signValidity;
		}


		/// <summary>
		/// 将结果集映射成实体对象
		/// </summary>
		/// <param name = "reader">只进结果集流</param>
		/// <return></return>
		public TSignInfoEO MapRow(IDataReader reader)
		{
			var ret = new TSignInfoEO();
			ret.SignId = (string)reader["sign_id"];
			ret.SignType = (string)reader["sign_type"];
			ret.SignClass = (string)reader["sign_class"];
			ret.SignImage = (byte[])reader["sign_image"];
			ret.SignContent = (string)reader["sign_content"];
			ret.SignDefence = (string)reader["sign_defence"];
			ret.SignValidity = (reader["sign_validity"] is DBNull) ? null : (int?)reader["sign_validity"];
			return ret;
		}

		/// <summary>
		/// 将结果集映射成实体对象，返回映射方法
		/// </summary>
		/// <return></return>
		public Func<IDataReader, TSignInfoEO> GetMapper()
		{
			return MapRow;
		}


	}


	#endregion
	#region MO

	/// <summary>
	///  《dbo.T_Sign_Info(逻辑类)》
	/// </summary>
	public class TSignInfoMO : DbManagerBase
	{

		#region 构造函数
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "routeData">路由数据</param>
		public TSignInfoMO(object routeData = null) : base(routeData) { }

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "connectionStringName">连接字符串名称</param>
		public TSignInfoMO(string connectionStringName) : base(connectionStringName) { }

		#endregion

		#region 私有方法
		/// <summary>
		/// 数据库访问操作方法
		/// </summary>
		/// <param name = "sql">SQL语句</param>
		/// <return>返回数据操作对象</return>
		private DbAdoBase AdoBase(string sql)
		{
			return DataBase.CreateDbAdo(sql, CommandType.Text);
		}

		#endregion

		#region Select方法集合

		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "signId"></param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<TSignInfoEO> SelectBySignId(string signId, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [sign_id], [sign_type], [sign_class], [sign_image], [sign_content], [sign_defence], [sign_validity] FROM [dbo].[T_Sign_Info] WHERE [sign_id]=@SignId");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@SignId", signId, DbType.AnsiStringFixedLength, 2)
							.ExecuteList(new TSignInfoEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "signType"></param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<TSignInfoEO> SelectBySignType(string signType, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [sign_id], [sign_type], [sign_class], [sign_image], [sign_content], [sign_defence], [sign_validity] FROM [dbo].[T_Sign_Info] WHERE [sign_type]=@SignType");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@SignType", signType, DbType.AnsiString, 10)
							.ExecuteList(new TSignInfoEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "signClass"></param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<TSignInfoEO> SelectBySignClass(string signClass, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [sign_id], [sign_type], [sign_class], [sign_image], [sign_content], [sign_defence], [sign_validity] FROM [dbo].[T_Sign_Info] WHERE [sign_class]=@SignClass");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@SignClass", signClass, DbType.AnsiString, 10)
							.ExecuteList(new TSignInfoEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "signImage"></param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<TSignInfoEO> SelectBySignImage(byte[] signImage, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [sign_id], [sign_type], [sign_class], [sign_image], [sign_content], [sign_defence], [sign_validity] FROM [dbo].[T_Sign_Info] WHERE [sign_image]=@SignImage");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@SignImage", signImage, DbType.Binary, 16)
							.ExecuteList(new TSignInfoEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "signContent"></param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<TSignInfoEO> SelectBySignContent(string signContent, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [sign_id], [sign_type], [sign_class], [sign_image], [sign_content], [sign_defence], [sign_validity] FROM [dbo].[T_Sign_Info] WHERE [sign_content]=@SignContent");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@SignContent", signContent, DbType.AnsiString, 16)
							.ExecuteList(new TSignInfoEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "signDefence"></param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<TSignInfoEO> SelectBySignDefence(string signDefence, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [sign_id], [sign_type], [sign_class], [sign_image], [sign_content], [sign_defence], [sign_validity] FROM [dbo].[T_Sign_Info] WHERE [sign_defence]=@SignDefence");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@SignDefence", signDefence, DbType.AnsiString, 16)
							.ExecuteList(new TSignInfoEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "signValidity"></param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<TSignInfoEO> SelectBySignValidity(int? signValidity, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [sign_id], [sign_type], [sign_class], [sign_image], [sign_content], [sign_defence], [sign_validity] FROM [dbo].[T_Sign_Info] WHERE [sign_validity]=@SignValidity");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@SignValidity", signValidity, DbType.Int32, 4)
							.ExecuteList(new TSignInfoEO().GetMapper(), tm);
		}

		/// <summary>
		/// 按自定义条件查询
		/// </summary>
		/// <param name = "where">自定义条件,where子句</param>
		/// <param name = "top">获取行数</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<TSignInfoEO> Select(string where, int top, string sort, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [sign_id], [sign_type], [sign_class], [sign_image], [sign_content], [sign_defence], [sign_validity] FROM [dbo].[T_Sign_Info] ");
			if (!string.IsNullOrEmpty(where)) format.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddParameters(paras)
							.ExecuteList(new TSignInfoEO().GetMapper(), tm);
		}

		/// <summary>
		/// 分页查询
		/// </summary>
		/// <param name = "where">条件表达式</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">传入参数</param>
		/// <param name = "pageSize">页大小</param>
		/// <param name = "pageIndex">页码</param>
		/// <param name = "recordCount">总记录数，由于计算总记录数影响数据库性能，只有小于或等于0的情况下才返回总记录数</param>
		/// <return>分页数据</return>
		public List<TSignInfoEO> SelectPager(string where, string sort, IList<DbParameter> paras, long pageSize, long pageIndex, ref long recordCount)
		{
			var sql = new StringBuilder();
			sql.AppendFormat(@"SELECT [sign_id], [sign_type], [sign_class], [sign_image], [sign_content], [sign_defence], [sign_validity] FROM [dbo].[T_Sign_Info]");
			if (!string.IsNullOrEmpty(where)) sql.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) sql.AppendFormat(" ORDER BY {0} ", sort);
			var pager = this.DataBase.CreatePager(sql.ToString(), pageSize);
			pager.AddParameters(paras);
			if (recordCount <= 0)
			{
				recordCount = pager.GetRecordCount();
			}
			return pager.GetPageData(pageIndex).MapToList(new TSignInfoEO().GetMapper());
		}

		#endregion

		#region Insert方法集合
		/// <summary>
		/// 插入数据，有自增列时，item中自增字段为新增值，否则，返回影响的行数
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "item">要插入的实体对象</param>
		/// <return></return>
		public int Insert(TSignInfoEO item, TransactionManager tm = null)
		{
			const string sql = @"INSERT INTO [dbo].[T_Sign_Info] ([sign_id], [sign_type], [sign_class], [sign_image], [sign_content], [sign_defence], [sign_validity]) VALUES (@sign_id, @sign_type, @sign_class, @sign_image, @sign_content, @sign_defence, @sign_validity) ";
			return AdoBase(sql)
												.AddInParameter("@sign_id", item.SignId, DbType.AnsiStringFixedLength, 2)
												.AddInParameter("@sign_type", item.SignType, DbType.AnsiString, 10)
												.AddInParameter("@sign_class", item.SignClass, DbType.AnsiString, 10)
												.AddInParameter("@sign_image", item.SignImage, DbType.Binary, 16)
												.AddInParameter("@sign_content", item.SignContent, DbType.AnsiString, -1)
												.AddInParameter("@sign_defence", item.SignDefence, DbType.AnsiString, -1)
												.AddInParameter("@sign_validity", item.SignValidity.HasValue ? (object)item.SignValidity.Value : DBNull.Value, DbType.Int32, 4)
												.ExecuteNonQuery(tm);
		}
		#endregion

		#region Update方法集合
		/// <summary>
		/// 按自定义条件更新数据
		/// </summary>
		/// <param name = "set">更新列</param>
		/// <param name = "where">更新条件</param>
		/// <param name = "paras">参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Update(string set, string where, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			if (string.IsNullOrEmpty(set)) throw new ArgumentNullException("set");
			var sql = string.Format(@"UPDATE [dbo].[T_Sign_Info] SET {0} {1}", set, (string.IsNullOrEmpty(where) ? string.Empty : " WHERE " + where));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region Delete方法集合
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "signId"></param>
		public int DeleteBySignId(string signId, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[T_Sign_Info] WHERE [sign_id]=@sign_id";
			return AdoBase(sql)
							.AddInParameter("@sign_id", signId, DbType.AnsiStringFixedLength, 2)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "signType"></param>
		public int DeleteBySignType(string signType, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[T_Sign_Info] WHERE [sign_type]=@sign_type";
			return AdoBase(sql)
							.AddInParameter("@sign_type", signType, DbType.AnsiString, 10)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "signClass"></param>
		public int DeleteBySignClass(string signClass, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[T_Sign_Info] WHERE [sign_class]=@sign_class";
			return AdoBase(sql)
							.AddInParameter("@sign_class", signClass, DbType.AnsiString, 10)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "signImage"></param>
		public int DeleteBySignImage(byte[] signImage, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[T_Sign_Info] WHERE [sign_image]=@sign_image";
			return AdoBase(sql)
							.AddInParameter("@sign_image", signImage, DbType.Binary, 16)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "signContent"></param>
		public int DeleteBySignContent(string signContent, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[T_Sign_Info] WHERE [sign_content]=@sign_content";
			return AdoBase(sql)
							.AddInParameter("@sign_content", signContent, DbType.AnsiString, -1)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "signDefence"></param>
		public int DeleteBySignDefence(string signDefence, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[T_Sign_Info] WHERE [sign_defence]=@sign_defence";
			return AdoBase(sql)
							.AddInParameter("@sign_defence", signDefence, DbType.AnsiString, -1)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "signValidity"></param>
		public int DeleteBySignValidity(int? signValidity, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[T_Sign_Info] WHERE [sign_validity]=@sign_validity";
			return AdoBase(sql)
							.AddInParameter("@sign_validity", signValidity.HasValue ? (object)signValidity.Value : DBNull.Value, DbType.Int32, 4)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 删除指定条件的记录
		/// </summary>
		/// <param name = "whereClause">自定义删除条件，where子句。如：id=1 and name='aaa'</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Delete(string whereClause, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = string.Format(@"DELETE FROM [dbo].[T_Sign_Info] {0}", (string.IsNullOrEmpty(whereClause) ? string.Empty : " WHERE " + whereClause));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region  自定义方法集合
		#endregion

	}


	#endregion
}
